//
//  FindModelFrame.m
//  庐山通
//
//  Created by zcj on 15-10-24.
//  Copyright (c) 2015年 郑朝军. All rights reserved.
//
/***
 command + delete
 ctr+k
 ------解决方案--------------------
 Ctrl + F ：前移光标
 Ctrl + B ：后移光标
 Ctrl + P ：移动光标到上一行
 Ctrl + N：移动光标到下一行
 Ctrl + A : 移动光标到本行行首
 Ctrl + E : 移动光标到本行行尾
 Ctrl + T ：交换光标左右两边的字符
 Ctrl + D：删除光标右边的字符
 Ctrl + K ：删除本行
 Ctrl + L : 将插入点置于窗口正中

 ****/
#import "FindModelFrame.h"
#import "Grouble.h"
#import "FindModel.h"
#import "GoodInforModel.h"
// 间隙
#define margen 10
// 单元格的宽
#define CellW (ScreenWidth - margen*3)*0.5
@implementation FindModelFrame
- (void)setFindModel:(FindModel *)findModel
{
    _findModel = findModel;
    CGFloat imgX = 0;
    CGFloat imgY = 0;
    CGFloat imgW = CellW;
    CGFloat imgH = imgW;
    _imageF=CGRectMake(imgX, imgY, imgW, imgH);
    //5.设置showView的frame
   
    CGFloat goodNameX = margen;
    CGFloat goodNameY = CGRectGetMaxY(_imageF) + margen;
    CGFloat goodNameW = CellW - margen *2;
   
    NSString * goodNameSub =[self subStrFromFitScreen:findModel.goods_name];
    // 返回文本绘制所占据的矩形空间
    CGSize goodNameWH = [goodNameSub boundingRectWithSize:CGSizeMake(goodNameW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
    
    _descF = CGRectMake(goodNameX, goodNameY, goodNameW, goodNameWH.height);
    
    // 设置价格
    CGFloat priceX = margen;
    CGFloat priceY = CGRectGetMaxY(_descF) + margen;
    
    CGSize priceWH = [findModel.goods_display_final_price sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]}];
    
    _priceF = CGRectMake(priceX, priceY, priceWH.width, priceWH.height);
    
    // 来源
    CGFloat sourceX = margen;
    CGFloat sourceY = CGRectGetMaxY(_priceF)+margen;
    CGSize sourceWH = [findModel.group_info.country sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]}];
    
    _addressF = CGRectMake(sourceX, sourceY, sourceWH.width, sourceWH.height);
    
    _cellH = CGRectGetMaxY(_addressF)+10;
    _showF=CGRectMake(0, 0, CellW, _cellH);
    
}
- (NSString *)subStrFromFitScreen:(NSString *)str
{
    NSString * tempStr = nil;
    if (ScreenWidth <= 320) {
        if(str.length>21){
            tempStr=[str substringToIndex:21];
        }else{
            tempStr=str;
        }
    }else if (ScreenWidth >= 320 && ScreenWidth <= 375){
        if(str.length>28){
            // 字符串截取到第n位
            tempStr=[str substringToIndex:28];
        }else{
            tempStr=str;
        }
    }else {
        if(str.length>32){
            tempStr=[str substringToIndex:32];
        }else{
            tempStr=str;
        }
    }
    return tempStr;
}
@end
